package com.web44.ssm.config;

import com.web44.ssm.filter.CrosFilter;
import jakarta.servlet.Filter;
import jakarta.servlet.MultipartConfigElement;
import jakarta.servlet.ServletRegistration;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

/**
 * @Title: ServletConfig
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2024/2/18 9:38
 */
public class ServletConfig extends AbstractAnnotationConfigDispatcherServletInitializer {

    /**
     * 整合spring相关
     * @return
     */
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }

    /**
     * 整合springmvc相关的
     * @return
     */
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        // 拦截所有 但是不包含静态资源 jsp
        return new String[]{"/"};
    }

    @Override
    protected Filter[] getServletFilters() {
        CrosFilter crosFilter = new CrosFilter();
        return new Filter[]{crosFilter};
    }

    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic registration) {
        registration.setMultipartConfig(new MultipartConfigElement("D:\\00.班级\\web44\\02.javaweb\\MySsmDemo\\src\\main\\webapp"));
    }
}
